import 'package:json_annotation/json_annotation.dart';

part 'daily_quiz.g.dart';

@JsonSerializable()
class DailyQuiz {
  final String id;
  final DateTime date;
  final List<String> questionIds;
  final int totalQuestions;
  final int correctAnswers;
  final double accuracy;
  final Duration duration;
  final DateTime completedAt;
  final bool isCompleted;

  const DailyQuiz({
    required this.id,
    required this.date,
    required this.questionIds,
    required this.totalQuestions,
    required this.correctAnswers,
    required this.accuracy,
    required this.duration,
    required this.completedAt,
    required this.isCompleted,
  });

  factory DailyQuiz.fromJson(Map<String, dynamic> json) => _$DailyQuizFromJson(json);
  Map<String, dynamic> toJson() => _$DailyQuizToJson(this);

  DailyQuiz copyWith({
    String? id,
    DateTime? date,
    List<String>? questionIds,
    int? totalQuestions,
    int? correctAnswers,
    double? accuracy,
    Duration? duration,
    DateTime? completedAt,
    bool? isCompleted,
  }) {
    return DailyQuiz(
      id: id ?? this.id,
      date: date ?? this.date,
      questionIds: questionIds ?? this.questionIds,
      totalQuestions: totalQuestions ?? this.totalQuestions,
      correctAnswers: correctAnswers ?? this.correctAnswers,
      accuracy: accuracy ?? this.accuracy,
      duration: duration ?? this.duration,
      completedAt: completedAt ?? this.completedAt,
      isCompleted: isCompleted ?? this.isCompleted,
    );
  }

  static DailyQuiz createNew(DateTime date, List<String> questionIds) {
    return DailyQuiz(
      id: 'daily_${date.year}_${date.month}_${date.day}',
      date: date,
      questionIds: questionIds,
      totalQuestions: questionIds.length,
      correctAnswers: 0,
      accuracy: 0.0,
      duration: Duration.zero,
      completedAt: DateTime.now(),
      isCompleted: false,
    );
  }
} 